﻿using System;

using Hjt212Parser;
using log4net;

namespace GatewayBizProcess.Facade
{
    public class Downline
    {
        //创建日志记录组件实例  
        private  static readonly ILog Log = LogManager.GetLogger(typeof(Downline));
        public void SendData(object state)
        {
            while (true)
            {
                var now = DateTime.Now;
                try
                {
                    CommandDown.Down2011();
                    CommandDown.Down2061();
                    CommandDown.Down3093();
                    CommandDown.Down3094();
                }
                catch (Exception ex)
                {
                    Log.Error( ex);
                }
                finally
                {
                    var span = (int)(DateTime.Now - now).TotalSeconds;

                    var milliSeconds = 1 * 60 * 1000 - span;
                    if (milliSeconds < 0)
                    {
                        Log.Info("下发一遍2011、2061、3093、3094需要" + span + "秒");
                        milliSeconds = 1000;
                    }
                    ThreadUtil.Sleep(milliSeconds);
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }
        public void SendCtrCmd(object state)
        {
            while (true)
            {
                try
                {
                    CommandDown.Down3051_3097();
                    CommandDown.Down3012();
                }
                catch (Exception ex)
                {
                    Log.Error( ex);
                }
                finally
                {
                    ThreadUtil.Sleep(1000);
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }
    }
}
